/**
 * 对象的混入 合并A对象 B对象 合并到一起
 * 类的混入 A类 B类 合并到一起
 */

interface A {
    age:number
}
interface B {
    name:string
}

/**
 * 对象的混入
 */
let a:A = {
    age:12
}
let b:B = {
    name:'zhou'
}
//扩展运算符 浅拷贝  返回新的类型
let c = {...a,...b}
console.log(c)
// Object.assign()  浅拷贝  返回的是交叉类型( A & B)
let  c2 = Object.assign({},a,b)
console.log(c2);
//实现深拷贝  node18以上  谷歌90以上 structuredClone(a,b)


/**
 * 类的混入(插件类型的混入)
 */
//插件1
class Logger {
    log(msg:string){
        console.log(msg)
    }
}
//插件2
class htmlRender{
    render(){
        console.log('render')
    }
}
class App {
    run(){
        console.log('run')
    }
}
type Custructor<T> = new (...args:any[]) => T
function pluginMixins <T extends Custructor<App>>(Base:T){
    return class extends Base {
        private Logger = new Logger()
        private HtmlRnder = new htmlRender()

        constructor(...args:any[]) {
            super(args);
            this.Logger = new Logger()
            this.HtmlRnder = new htmlRender()
        }
        run(){
            console.log(this.Logger.log('run'));
        }
        render(){
            this.Logger.log('render--run')
            this.HtmlRnder.render()
        }
    }
}
const Mixins = pluginMixins(App)
const app = new Mixins
app.run()
app.render()